package com.zhentao.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.model.common.enums.AppHttpCodeEnum;
import com.zhentao.model.common.vo.FeedbackVo;
import com.zhentao.model.complaint.dto.ComplaintDto;
import com.zhentao.model.complaint.pojo.AdComplaint;
import com.zhentao.model.complaint.vo.ComplaintVo;
import com.zhentao.service.AdComplaintService;
import com.zhentao.mapper.AdComplaintMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
* @author 许文倩
* @description 针对表【ad_complaint】的数据库操作Service实现
* @createDate 2024-07-08 16:07:32
*/
@Service
public class AdComplaintServiceImpl extends ServiceImpl<AdComplaintMapper, AdComplaint>
    implements AdComplaintService{
    @Resource
    AdComplaintMapper adComplaintMapper;

    @Override
    public PageInfo<ComplaintVo> complaintList(ComplaintDto dto) {
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        List<ComplaintVo> complaintVo=adComplaintMapper.complaintList();
        PageInfo<ComplaintVo> complaintVoPageInfo=new PageInfo<>(complaintVo);
        return complaintVoPageInfo;
    }

    @Override
    public ResponseResult add(AdComplaint complaint) {
        complaint.setAuditSataus(0);
        complaint.setCreatedTime(new Date());
        adComplaintMapper.insert(complaint);
        return ResponseResult.okResult("提交成功");
    }

    @Override
    public PageInfo<ComplaintVo> notChecklist(ComplaintDto dto) {
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        List<ComplaintVo> complaintVo=adComplaintMapper.notChecklist();
        PageInfo<ComplaintVo> complaintVoPageInfo=new PageInfo<>(complaintVo);
        return complaintVoPageInfo;
    }

//    @Override
//    public ResponseResult loser(ComplaintDto dto) {
//        if (dto==null || dto.getId()==null){
//            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
//        }
//        AdComplaint adComplaint= getById(dto.getId());
//        if (adComplaint==null){
//            return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST,"动态不存在");
//        }
//        adComplaint.setFeedback(2);
//        adComplaintMapper.updateById(adComplaint);
//        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
//    }

    @Override
    public ResponseResult status(ComplaintDto dto) {

        AdComplaint adComplaint = getById(dto.getId());
        if (adComplaint==null){
            return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST,"投诉不存在");
        }
        adComplaint.setAuditSataus(1);
        adComplaint.setFeedback(dto.getFeedback());
        adComplaintMapper.updateById(adComplaint);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    @Override
    public ResponseResult getFeedback(Integer userId) {
        List<FeedbackVo> feedback= adComplaintMapper.getFeedback(userId);
        return ResponseResult.okResult(feedback);
    }

    public AdComplaint getById(Integer id){
        AdComplaint adComplaint = adComplaintMapper.selectById(id);
        return adComplaint;
    }
}




